#ifndef SHEETWIDGET_H
#define SHEETWIDGET_H

#include <QWidget>
#include <QVariantMap>
#include <QSortFilterProxyModel>

#include "interfaces.h"
#include "abilitylistmodel.h"
#include "characterabilitymodel.h"

namespace Ui {
    class SheetWidget;
}

class SheetWidget : public WidgetWithGdrData
{
    Q_OBJECT

public:
    explicit SheetWidget(QObject* chModel = 0, QWidget *parent = 0);
    ~SheetWidget();

    void setGdrData(QVariantMap *data);
    QObject * chModel();

    void refreshFromData(QObject* ch);
    void updateData(QObject* ch);

    virtual void beginLoadFrom()    { _is_loading = true;   }
    virtual void endLoadFrom()      { _is_loading = false;  }

protected:
    AbilityListModel alm;
    CharacterAbilityModel cam;
    QSortFilterProxyModel sortcam;

    QVariantMap* gdrData;
    QObject* ch;

    bool _is_loading;
    bool _ab_sort_enabled;

private slots:
    void on_pbLock_toggled(bool checked);
    void getOccupationBenefits(QString /*Occupation Name*/);
    void onIntPropertyChanged(QString /*Prop name*/);
    void updateOccupBenefits();

    void on_pbAddSkill_clicked();
    void on_pbRemoveSkill_clicked();

    void spendBuildPoints(int points);
    void spendInvestigationPoints(int points);

    void checkHealthAbility();
    void comboSelectOccup(QString);
    void comboSelectDrive(QString);

    void on_pbResetPool_clicked();

    void on_tvAbilities_customContextMenuRequested(QPoint pos);

private:
    Ui::SheetWidget *ui;

    // HELPERS
    void setupCompleters();
    void setupFreePoints();
    void setupAbilities();
    void setupAbilities(QString, QString, QVariantList);

    bool canSpendBuildPoints(int points);
    bool canSpendInvestigationPoints(int points);

    QVariantList extractOccupAbilities(QString);
    bool askToChangeOccupation();
    QString askToChooseAbility(QString filter);       
};

#endif // SHEETWIDGET_H
